package com.jinsi.controller.tang;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jinsi.constant.YltConstant;
import com.jinsi.pojo.Commodity;
import com.jinsi.service.tang.PersonalProductListService;
import com.jinsi.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 个人商品列表
 * @author 唐文博
 * @Date 2022-08-13
 */
@RestController
@RequestMapping("/personalProductList")
public class PersonalProductListController {
    @Autowired
    private PersonalProductListService personalProductListService;

    /**
     * 筛选搜索查询
     * @param page
     * @param limit
     * @param session
     * @return
     */
    @RequestMapping("/getPersonalProductListSee")
    public R getPersonalProductListSee(Integer page, Integer limit,HttpSession session){
        PageHelper.startPage(page,limit);
        List<Commodity> list = personalProductListService.getPersonalProductListSee(session);
        PageInfo<Commodity> pageInfo = new PageInfo<>(list);
        return R.custom(YltConstant.LAYUI_CODE,
                YltConstant.LAYUI_MSG,
                pageInfo.getList(),
                pageInfo.getTotal());
    }

    /**
     * 筛选搜索查询,根据商品名称、商品关键字、上传人名称查询
     * @param page
     * @param limit
     * @param commodityName
     * @param classifyTitle
     * @param commodityLabel
     * @param session
     * @return
     */
    @RequestMapping("/getPersonalProductListLike")
    public R getPersonalProductListLike(Integer page,Integer limit,String commodityName,
                                             String classifyTitle,String commodityLabel,
                                        HttpSession session){
        PageHelper.startPage(page,limit);
        List<Commodity> list = personalProductListService.getPersonalProductListLike(commodityName,
                classifyTitle,commodityLabel,session);
        PageInfo<Commodity> pageInfo = new PageInfo<>(list);
        return R.custom(YltConstant.LAYUI_CODE,
                YltConstant.LAYUI_MSG,
                pageInfo.getList(),
                pageInfo.getTotal());
    }
}
